﻿cmake_minimum_required (VERSION 3.0)

project(eigen_sparse_matrix)


# 添加OpenCV_DIR变量，指向OpenCVConfig.cmake所在目录 
set(OpenCV_DIR "D:/OpenCV/opencv/build/x64/vc16/lib")  # 根据实际安装路径修改

# 查找OpenCV包
find_package(OpenCV REQUIRED)

# 包含OpenCV头文件目录
include_directories(${OpenCV_INCLUDE_DIRS})
# 自动复制OpenCV DLL到输出目录
if(WIN32)
    # 获取OpenCV DLL路径
    get_filename_component(OpenCV_RUNTIME_DIR "D:/OpenCV/opencv/build/x64/vc16/bin" ABSOLUTE)
    
    # 复制调试版本的DLL（带'd'后缀）
    file(GLOB OpenCV_DLLS_DEBUG "${OpenCV_RUNTIME_DIR}/*d.dll")
    
    # 复制发布版本的DLL
    file(GLOB OpenCV_DLLS_RELEASE "${OpenCV_RUNTIME_DIR}/*.dll")
    list(FILTER OpenCV_DLLS_RELEASE EXCLUDE REGEX ".*d.dll$")
    
    # 根据构建类型复制对应的DLL
    if(CMAKE_BUILD_TYPE MATCHES "Debug")
        file(COPY ${OpenCV_DLLS_DEBUG} DESTINATION ${CMAKE_BINARY_DIR})
    else()
        file(COPY ${OpenCV_DLLS_RELEASE} DESTINATION ${CMAKE_BINARY_DIR})
    endif()
endif()
# 寻找 Eigen3 库
find_package (Eigen3 REQUIRED NO_MODULE)


add_library(eigen_sparse_matrix eigen_sparse_matrix.cpp)
target_link_libraries(eigen_sparse_matrix Eigen3::Eigen)
target_link_libraries(eigen_sparse_matrix ${OpenCV_LIBS})
# 链接其他静态库
# target_include_directories(genetic_algorithm PRIVATE ../Louvain)

# 将头文件链接到所生成的库中
target_include_directories(eigen_sparse_matrix PRIVATE ${OpenCV_INCLUDE_DIRS})
target_include_directories(eigen_sparse_matrix PUBLIC ./)

# 包含所需的头文件(standard.h)
target_include_directories(eigen_sparse_matrix PRIVATE ../..)